/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.lostreseditores.modelo;

import java.io.Serializable;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author DILOVE
 */
@Entity
@Table(name = "gradoinstitucion")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Gradoinstitucion.findAll", query = "SELECT g FROM Gradoinstitucion g"),
    @NamedQuery(name = "Gradoinstitucion.findByIdInstitucion", query = "SELECT g FROM Gradoinstitucion g WHERE g.gradoinstitucionPK.idInstitucion = :idInstitucion"),
    @NamedQuery(name = "Gradoinstitucion.findByIdGrado", query = "SELECT g FROM Gradoinstitucion g WHERE g.gradoinstitucionPK.idGrado = :idGrado")})
public class Gradoinstitucion implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected GradoinstitucionPK gradoinstitucionPK;
    @JoinColumn(name = "id_institucion", referencedColumnName = "id_institucion", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Institucion institucion;
    @JoinColumn(name = "id_grado", referencedColumnName = "id_grado", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Grado grado;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "gradoinstitucion")
    private List<Curso> cursoList;

    public Gradoinstitucion() {
    }

    public Gradoinstitucion(GradoinstitucionPK gradoinstitucionPK) {
        this.gradoinstitucionPK = gradoinstitucionPK;
    }

    public Gradoinstitucion(int idInstitucion, int idGrado) {
        this.gradoinstitucionPK = new GradoinstitucionPK(idInstitucion, idGrado);
    }

    public GradoinstitucionPK getGradoinstitucionPK() {
        return gradoinstitucionPK;
    }

    public void setGradoinstitucionPK(GradoinstitucionPK gradoinstitucionPK) {
        this.gradoinstitucionPK = gradoinstitucionPK;
    }

    public Institucion getInstitucion() {
        return institucion;
    }

    public void setInstitucion(Institucion institucion) {
        this.institucion = institucion;
    }

    public Grado getGrado() {
        return grado;
    }

    public void setGrado(Grado grado) {
        this.grado = grado;
    }

    @XmlTransient
    public List<Curso> getCursoList() {
        return cursoList;
    }

    public void setCursoList(List<Curso> cursoList) {
        this.cursoList = cursoList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (gradoinstitucionPK != null ? gradoinstitucionPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Gradoinstitucion)) {
            return false;
        }
        Gradoinstitucion other = (Gradoinstitucion) object;
        if ((this.gradoinstitucionPK == null && other.gradoinstitucionPK != null) || (this.gradoinstitucionPK != null && !this.gradoinstitucionPK.equals(other.gradoinstitucionPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.lostreseditores.modelo.Gradoinstitucion[ gradoinstitucionPK=" + gradoinstitucionPK + " ]";
    }
    
}
